<?php

namespace App\Admin\Controllers\Data;

use App\Enums\RefundState;
use App\Models\Refund;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class RefundController extends AdminController
{
    protected string $title = '退款';

    public function grid(): Grid
    {
        return Grid::make(Refund::with(['order'])->ofAdmin(), function (Grid $grid) {
            $grid->disableCreateButton();

            if (Admin::user()->isAdministrator()) {
                $grid->column('application.name', '所属应用');
            }

            $grid->column('order.no', '支付单号')
                ->copyable();
            $grid->column('no', '退款单号')
                ->copyable();
            $grid->column('amount', '退款金额');
            $grid->column('state', '退款状态')
                ->using(RefundState::STATE_MAP)
                ->label(RefundState::STATE_LABEL);
            $grid->column('refunded_at', '退款时间');
            $grid->column('created_at', '申请时间');
        });
    }
}
